package com.epfresh.supplier.activity.standingbook;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aigestudio.wheelpicker.core.AbstractWheelPicker;
import com.aigestudio.wheelpicker.widget.curved.WheelDatePicker;
import com.epfresh.supplier.R;

/**
 * Created by shenjie on 2017/10/11.
 */

public class ListTimeDatePicker extends PopupWindow implements View.OnClickListener{
    private Context context;
    ListView listViewTime;
    StandingBookActivity.TimeAdapter adapter;
    AnimationEndListener listener;
    private boolean need;

    public AnimationEndListener getListener() {
        return listener;
    }

    public void setListener(AnimationEndListener listener) {
        this.listener = listener;
    }

    RelativeLayout rlTime;
    public  ListTimeDatePicker(Context context,
            StandingBookActivity.TimeAdapter adapter){
        this.context=context;
        this.adapter=adapter;
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setBackgroundDrawable(new ColorDrawable(0x00000000));
        setAnimationStyle(R.style.popwin_bottom_style);
        initView();
    }

    private void initView(){
        View view= LayoutInflater.from(context).inflate(R.layout.pop_listtime,null);
        setContentView(view);
        listViewTime= (ListView) view.findViewById(R.id.lv_time);
        rlTime= (RelativeLayout) view.findViewById(R.id.rl_time);
        rlTime.setOnClickListener(this);
        if (adapter!=null){
            listViewTime.setAdapter(adapter);
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_time:
                need=false;
                viewOut();
                break;
        }
    }

    public  void viewIn() {
        listViewTime.setVisibility(View.VISIBLE);
        ScaleAnimation animation =new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
                Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
        animation.setDuration(300);
        listViewTime.setAnimation(animation);
    }
    public  void viewOut(){
//        listViewTime.setVisibility(View.INVISIBLE);
//        ScaleAnimation animation =new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f,
//                Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);
//        animation.setDuration(600);
//        animation.setAnimationListener(new Animation.AnimationListener() {
//            @Override
//            public void onAnimationStart(Animation animation) {
//
//            }
//
//            @Override
//            public void onAnimationEnd(Animation animation) {
//                dismiss();
//                if(listener!=null){
//                    listener.load(need);
//                }
//            }
//
//            @Override
//            public void onAnimationRepeat(Animation animation) {
//
//            }
//        });
//        listViewTime.setAnimation(animation);
        dismiss();
        if(listener!=null){
            listener.load(need);
        }
    }

    interface  AnimationEndListener{
        public void load(boolean need);
    }

    public boolean isNeed() {
        return need;
    }

    public void setNeed(boolean need) {
        this.need = need;
    }
}
